﻿#include "stdafx.h"

#include "Dialog.h"
#include "ui_Dialog.h"
#include "FrameHelper.h"
#include "TitleBar.h"

Dialog::Dialog(QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog)
{
	ui->setupUi(this);
	setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);

	initDialog();
}

Dialog::~Dialog()
{
	delete pFrameHelper;
	delete ui;
}

/***********************************************************************************************************************************/
void Dialog::setWidget(QWidget * pWdiget)
{
	ui->mainLayout->addWidget(pWdiget);
	ui->mainLayout->setContentsMargins(0, 0, 0, 0);
	connect(pWdiget, SIGNAL(closeWidget()), this, SLOT(close()));
}

void Dialog::setTitle(const QString & strTitle)
{
	ui->labTitle->setText(strTitle);
}

void Dialog::setMinBtnVisible(bool visible)
{
	ui->btnMin->setVisible(visible);
}

void Dialog::setMaxBtnVisible(bool visible)
{
	ui->btnMax->setVisible(visible);
}

/***********************************************************************************************************************************/
void Dialog::initDialog()
{
	pFrameHelper = new FrameHelper(this);
	pFrameHelper->addEdgeWidget(this);
	pFrameHelper->addDragWidget(this);
	pFrameHelper->setCloseButton(ui->btnClose);
	pFrameHelper->setMinimizedButton(ui->btnMin);
	pFrameHelper->setMaxRestoreButton(ui->btnMax);
}